<script type="text/javascript" >
    stFacebookToolbox.sortColumn();
    stFacebookToolbox.shortAction();
    function toggleDiv(id, id1){
        stFacebookToolbox.loadPage('appPostcards', null, null, function(){
            toggleDiv('upload_field', 'uploadObject', 'createBucket');
        }); 
    }
    
    function exportCSV(){
        url='<?php echo home_url('/wp-content/plugins/stSocialMediaToolbox/Toolboxes/stFacebookToolbox/csv/postcard_user_export.php')?>';
        window.open(url)
//        var data = new Array();
//        data['short_action'] = 'export';
//        stFacebookToolbox.loadPage('appPostcardsUser', data); 
    }
</script>
<style type="text/css">
    #stcontainer .buttonActionContainer{
        left: 186px;
        margin-top: -30px;
        position: absolute;
    }
</style>
<div class="buttonActionContainer">
    <a href="javascript:stFacebookToolbox.loadPage('appPostcardsUserEdit')" onclick="" class="button add-new-h2 buttonAction">
        <?php _e('Create new User', $config['plugin_name']) ?>
    </a>
</div>
<div class="w100p bgl">
    <div class="w100p bgr">
        <div class="inner_container">
            <?php echo $functions->appPostcardMenu(); ?>
            <div class="filter float_right" style="margin: 5px 15px 5px 5px" >
                <input onclick="exportCSV()" type="button" 
                       style="width: 120px; color: green; font-weight: bold; cursor: pointer; float:right;" 
                       class="button update_price" 
                       value="EXPORT CSV" /> 
            </div>
            <table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stFacebookToolbox_appPostCardUser'); ?>
                    </tr>
                </thead>

                <tbody>
                    <?php
                    if (count($results) > 0) {
                        $tr_class = "";
                        $upload_data = wp_upload_dir();
                        foreach ($results as $result) {
                            $time = explode(' ', $result->cdate);
                            $date = explode('-', $time[0]);
                            $date = $date[2] . '.' . $date[1] . '.' . $date[0];
                            $time = $time[1];
                            $cdate = $date . ' ' . $time;

                            if (empty($tr_class) || $tr_class == "class='bg_gray2'") {
                                $tr_class = "class='bg_gray1'";
                            } else {
                                $tr_class = "class='bg_gray2'";
                            }
                            $shared = empty($result->shared) ? 0 : $result->shared;
                            $shared_fb = empty($result->shared_fb) ? 0 : $result->shared_fb;
                            $shared_email = empty($result->shared_email) ? 0 : $result->shared_email;
                            $shared = $shared_fb + $shared_email;
                            $created = empty($result->created) ? 0 : $result->created;
                            echo "<tr id='$result->id' $tr_class >"
                            . "<td>" . $result->name
                            . "<div class=\"row-actions short_action\">"
                            . "<span class='edit' action='appPostcardsUserEdit' short_action='' id='$result->id'>Edit | </span>"
                            . "<span class='edit' action='' function='
                                var data = new Array();
                                data[\"user_id\"] = \"{$result->id}\";
                                data[\"folder\"] = \"{$config['folder_generated']}\"
                                stFacebookToolbox.loadPage(\"showUserCard\",data)
                                ' id='$result->id'>Show postcards | </span>"
                            . "<span class='trash' short_action='delete' id='$result->id' confirm='Are you sure you want to delete this user?'>Trash </span>"
                            . "</div>"
                            . "</td>"
//                        . "<td>" . $result->user_name . "</td>"                        
//                        . "<td>" . $result->name . "</td>"
                            . "<td>" . $result->email . "</td>"
                            . "<td align='center'>" . $created . "</td>"
                            . "<td align='center'>" . $shared . "</td>"
                            . "<td align='center'>" . $shared_fb . "</td>"
                            . "<td align='center'>" . $shared_email . "</td>"
                            . "<td>" . $cdate . "</td>"
                            . "</tr>"
                            ;
                        }
                    }
                    ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination ?>
                <div class="cl"></div>
            </div>

        </div>
    </div>
</div>